package com.javaweb.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javaweb.admin.entity.KdlSineGoodsmovementB;
import com.javaweb.admin.entity.KdlSineSoOutbound;
import com.javaweb.admin.entity.KdlSineSoOutboundB;
import com.javaweb.admin.query.KdlSineSoOutboundQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface KdlSineSoOutboundMapper extends BaseMapper<KdlSineSoOutbound> {

    IPage<KdlSineSoOutbound> getOutBoundList(IPage<KdlSineSoOutbound> page, @Param("req")KdlSineSoOutboundQuery req);

    @Select("select isnull(left(max(salesorderno),8)+right('000'+convert(varchar(3),convert(int,right(max(salesorderno),3))+1),3),'XH'+convert(varchar(6),getdate(),112)+'001') from kdl_sine_so_outbound")
    String getOrderNo();

    @Select("select * from v_kdl_sine_outboud where pid=${pid} order by itemcode,batch")
    List<KdlSineSoOutboundB> getOutboundDetail(Integer pid);

    @Select("select t1.*,t2.comdescription from kdl_sine_so_outbound_b t1 left join v_nc_invlist t2 on t1.itemcode=t2.materialcode where salesorderno=${salesorderno} order by itemcode,batch")
    List<KdlSineSoOutboundB> getDetailList(String salesorderno);

}
